package com.ljs.spring_fastdfs.config.uploadConfig;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration

public class MyWebAppConfigurer implements WebMvcConfigurer {
    //读取配置文件自定义的路径
    @Value("${myfile.staticAccessPath}")
    String staticAccessPath;
    @Value("${myfile.uploadFolder}")
    String uploadFolder;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("相对路径"+staticAccessPath);
        System.out.println("实际路径"+uploadFolder);
        //这个是本地的路径
        registry.addResourceHandler(staticAccessPath) //虚拟路径，前端显示要加 /img/图片路径
                .addResourceLocations("file:"+uploadFolder);
//        registry.addResourceHandler("/**") //拦截了全部，要把静态资源放开
//                .addResourceLocations("file:E:/images/")
//                .addResourceLocations("classpath:/resources/")
//                .addResourceLocations("classpath:/static/")
//                .addResourceLocations("classpath:/public/");




//        String linuxPath = "/usr/local/java/jar/images/";
//        //在Linux环境下的图片存放资源路径
//        registry.addResourceHandler("/images/**").
//                ///images/来访问图片
//                addResourceLocations("file:"+linuxPath);

    }
}
